package com.itheima.datastructure.stack;

public class E04Leetcode232 {
    /*
    向s2添加元素
    先把s2的元素移动到s1，再把s1的元素移除
     */
    ArrayStack<Integer> s1=new ArrayStack<>(100);
    ArrayStack<Integer> s2=new ArrayStack<>(100);

    //向队尾添加
    public void push(int x){
        s2.push(x);
    }

    //从队列头删除
    public int pop(){
        if(s1.isEmpty()){
            while(!s2.isEmpty()){
                s1.push(s2.pop());
            }
        }
        return s1.pop();
    }

    //返回队头元素
    public int peek(){
        if(s1.isEmpty()){
            while(!s2.isEmpty()){
                s1.push(s2.pop());
            }
        }
        return s1.peek();
    }

    public boolean empty(){
        return s1.isEmpty() && s2.isEmpty();
    }

}
